package com.parkinglot.service.Impl;

import com.parkinglot.dao.GaragePayConfigDao;
import com.parkinglot.parmeter.GaragePayConfigaddParm;
import com.parkinglot.pojo.GaragePayConfig;
import com.parkinglot.service.GaragePayConfigService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (GaragePayConfig)表服务实现类
 *
 * @author makejava
 * @since 2020-11-13 15:28:53
 */
@Service("garagePayConfigService")
public class GaragePayConfigServiceImpl implements GaragePayConfigService {
    @Resource
    private GaragePayConfigDao garagePayConfigDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public GaragePayConfig queryById(Integer id) {
        return this.garagePayConfigDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<GaragePayConfig> queryAllByLimit(int offset, int limit) {
        return this.garagePayConfigDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param garagePayConfigaddParm 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(GaragePayConfigaddParm garagePayConfigaddParm ) {
        int code=0;
        GaragePayConfig garagePayConfig=new GaragePayConfig();
        try {
            BeanUtils.copyProperties(garagePayConfigaddParm,garagePayConfig);
            code=garagePayConfigDao.insert(garagePayConfig);
        }catch (Exception e){
            e.printStackTrace();
        }

        return code;
    }

    /**
     * 修改数据
     *
     * @param garagePayConfig 实例对象
     * @return 实例对象
     */
    @Override
    public GaragePayConfig update(GaragePayConfig garagePayConfig) {
        this.garagePayConfigDao.update(garagePayConfig);
        return this.queryById(garagePayConfig.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.garagePayConfigDao.deleteById(id) > 0;
    }
}